//
//  VVEmoticon.swift
//  Weibo
//
//  Created by 王惠平 on 2017/4/7.
//  Copyright © 2017年 Will Wang. All rights reserved.
//

import UIKit

//表情模型
class VVEmoticon: NSObject, NSCoding {
    
    //表情描述,用于发微博的时候去使用,发送给后台的是表情描述,不是那个图片
    var chs: String?
    
    //图片名
    var png: String?
    
    //表情类型 0:图片表情 1:emoji表情
    var type: String?
    
    //emoji对应的code码- 16进制的字符串
    var code: String?
    
    //图片全路径
    var path: String?
    
    //图片对应的文件夹
    var folderName: String?
    
    //因为YYModel在给属性赋值的时候,需要使用默认的构造函数进行创建对象,对象创建完成以后才能使用kvc给属性赋值
    override init() {
        super.init()
    }
    
    //归档和解档
    func encode(with aCoder: NSCoder) {
        
        aCoder.encode(chs, forKey:"chs")
        aCoder.encode(png, forKey: "png")
        aCoder.encode(type, forKey: "type")
        aCoder.encode(code, forKey: "code")
        aCoder.encode(path, forKey: "path")
        aCoder.encode(folderName, forKey: "folderName")

    }

   required init?(coder aDecoder:NSCoder) {
        
    chs = aDecoder.decodeObject(forKey: "chs") as? String
    png = aDecoder.decodeObject(forKey: "png") as? String
    type = aDecoder.decodeObject(forKey: "type") as? String
    code = aDecoder.decodeObject(forKey: "code") as? String
    path = aDecoder.decodeObject(forKey: "path") as? String
    folderName = aDecoder.decodeObject(forKey: "folderName") as? String

    if type == "0" {
        
        //图片表情,需要获取最新的bundle路径加载图片
        path = VVEmoticonTools.sharedTools.emoticonBudle.path(forResource: folderName, ofType: nil)! + "/" + png!
    }
    }

}
